package com.qyhl.module_practice.newhome;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qyhl.module_practice.R;
import com.qyhl.webtv.basiclib.utils.DateUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeAcitivityBean;

import java.util.List;

public class PracticeGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<PracticeAcitivityBean> beanList;

    PracticeGridViewAdapter(Context context, List<PracticeAcitivityBean> list) {
        this.context = context;
        this.beanList = list;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.practice_item_home_rec, null);
            vh = new ViewHolder();
            vh.title = (TextView) view.findViewById(R.id.title);
            vh.cover = (ImageView) view.findViewById(R.id.cover);
            vh.endTime = (TextView) view.findViewById(R.id.end_time);
            vh.num = (TextView) view.findViewById(R.id.num);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        vh.title.setText(beanList.get(position).getName());
        Glide.with(context)
                .load(beanList.get(position).getLogo())
                .apply(new RequestOptions().error(R.drawable.cover_normal_default).placeholder(R.drawable.cover_normal_default))
                .into(vh.cover);

        vh.endTime.setText("招募截止：" + DateUtils.practiceRecFormat(beanList.get(position).getEndTime()));
        if (beanList.get(position).getQuantityDemanded() == 0) {
            vh.num.setText(beanList.get(position).getVolunteerNum() + "/不限");
        } else {
            vh.num.setText(beanList.get(position).getVolunteerNum() + "/" + beanList.get(position).getQuantityDemanded());
        }

        return view;
    }

    class ViewHolder {
        TextView title;
        TextView endTime;
        ImageView cover;
        TextView num;
    }
}
